package synchronized代码块的同步性;
class ObjectService{
	public void serviceMethodA() {
		try {
			synchronized(this)
			{
				System.out.println("A begin time=" + System.currentTimeMillis());
				Thread.sleep(2000);
				System.out.println("A end time=" + System.currentTimeMillis());
			}
		}catch(InterruptedException e) {
			e.printStackTrace();
		}
	}
		public void serviceMethodB() {
			try {
				synchronized(this)
				{
					System.out.println("B begin time=" + System.currentTimeMillis());
					Thread.sleep(2000);
					System.out.println("B end time=" + System.currentTimeMillis());
				}
			}catch(InterruptedException e) {
				e.printStackTrace();
			}
	}
}
	class ThreadA extends Thread{
		private ObjectService service;
		public ThreadA(ObjectService service) {
			super();
			this.service=service;
		}
		@Override
		public void run() {
			// TODO Auto-generated method stub
			super.run();
			service.serviceMethodA();
		}
		
	}
	class ThreadB extends Thread{
		private ObjectService service;
		public ThreadB(ObjectService service) {
			super();
			this.service=service;
		}
		@Override
		public void run() {
			// TODO Auto-generated method stub
			super.run();
			service.serviceMethodB();
		}
		
	}
public class Test2_26 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ObjectService task=new ObjectService();
		ThreadA a=new ThreadA(task);
		a.setName("A");
		a.start();
		ThreadB b=new ThreadB(task);
		b.setName("B");
		b.start();
		
	}

}
